//
//  IDVerfitySuccessController.m
//  ATMCash
//
//  Created by zhengchengfeng on 2024/9/12.
//

#import "IDVerfitySuccessController.h"

#import "PersonVertifyController.h"
#import "WorkInfoVertifyController.h"
#import "ContactVertifyController.h"
#import "BankVertifyController.h"

#define kFootViewHeight  (15 + 48 + (IS_IPhoneX_All ? kHeight_BottomSafe : 15))

@interface IDVerfitySuccessController ()

@end

@implementation IDVerfitySuccessController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}


- (void)back{
    [[self getCurrentVC] jumpToPopControlClass:@"OrderDetailViewController"];
}

- (void)initFootView{

    UIView *bottomV = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight - kFootViewHeight - kNavigationBarHeight, kScreenWidth, kFootViewHeight)];
    bottomV.backgroundColor = [UIColor clearColor];
    [self.view addSubview:bottomV];
    
    
    UIButton *nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(15, 15, kScreenWidth - 30, 48)];
    nextBtn.titleLabel.font = [UIFont fontWithName:kFuturaMedium size:16];
    [nextBtn setTitleColor:[UIColor colorWithHexString:@"#FFEFC2"] forState:UIControlStateNormal];
    [nextBtn setTitleColor:[UIColor colorWithHexString:@"#FFEFC2"] forState:UIControlStateSelected];
    [nextBtn setTitleColor:[UIColor colorWithHexString:@"#FFEFC2"] forState:UIControlStateHighlighted];
    [nextBtn setTitle:@"OK" forState:UIControlStateNormal];
    [nextBtn setTitle:@"OK" forState:UIControlStateSelected];
    [nextBtn setTitle:@"OK" forState:UIControlStateHighlighted];
    [nextBtn setBackgroundImage:[UIImage imageNamed:@"icon_idf4"] forState:UIControlStateNormal];
    [nextBtn setBackgroundImage:[UIImage imageNamed:@"icon_idf4"] forState:UIControlStateSelected];
    [nextBtn setBackgroundImage:[UIImage imageNamed:@"icon_idf4"] forState:UIControlStateHighlighted];
    [nextBtn addTarget:self action:@selector(clickOKBtn) forControlEvents:UIControlEventTouchUpInside];
    [bottomV addSubview:nextBtn];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"";
    self.view.backgroundColor = self.tableView.backgroundColor = RGB(4, 44, 8);
    
    self.tableView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - kFootViewHeight );
    
    [self initFootView];
    
    
    UIImage *bgImg = [UIImage imageNamed:@"icon_idf20"];
    UIImage *bgImg2 = [UIImage imageNamed:@"icon_idf21"];
    UIImage *bgImg3 = [UIImage imageNamed:@"icon_idf22"];
    
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, bgImg.size.height + DimensionBaseIphone6(bgImg3.size.height) + 10 + 15)];
    self.tableView.tableHeaderView = headView;
    
    UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, bgImg.size.height)];
    imgV.image = bgImg;
    [headView addSubview:imgV];
    
    UIImageView *backImgView2 = [[UIImageView alloc] initWithFrame:CGRectMake(15, imgV.bottom + 15, kScreenWidth - 30, DimensionBaseIphone6(bgImg3.size.height))];
    backImgView2.image = bgImg3;
    [headView addSubview:backImgView2];
    
    UIImage *ic1img = [UIImage imageNamed:@"icon_idf5"];
    UIImageView *ic1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, backImgView2.size.width, DimensionBaseIphone6(ic1img.size.height))];
    ic1.image = ic1img;
    [backImgView2 addSubview:ic1];
    
    UIImage *ic2img = [UIImage imageNamed:@"icon_idf3"];
    UIImageView *ic2 = [[UIImageView alloc] initWithFrame:CGRectMake((ic1.size.width - DimensionBaseIphone6(ic2img.size.width))/2, (ic1.size.height - DimensionBaseIphone6(ic2img.size.height))/2, ic2img.size.width, DimensionBaseIphone6(ic2img.size.height))];
    ic2.image = ic2img;
    [backImgView2 addSubview:ic2];
    
    UIButton *btn1 = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, backImgView2.size.width/2, ic1.size.height)];
    [btn1 setTitle:[NSString stringWithFormat:@"  %@",esString(self.cardStr)] forState:UIControlStateNormal];
    [btn1 setTitle:[NSString stringWithFormat:@"  %@",esString(self.cardStr)] forState:UIControlStateSelected];
    [btn1 setTitle:[NSString stringWithFormat:@"  %@",esString(self.cardStr)] forState:UIControlStateHighlighted];
    [btn1 setImage:[UIImage imageNamed:@"icon_idf1"] forState:UIControlStateNormal];
    [btn1 setImage:[UIImage imageNamed:@"icon_idf1"] forState:UIControlStateSelected];
    [btn1 setImage:[UIImage imageNamed:@"icon_idf1"] forState:UIControlStateSelected];
    [btn1 setTitleColor:[UIColor colorWithHexString:@"#FFEFC0"] forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor colorWithHexString:@"#FFEFC0"] forState:UIControlStateSelected];
    [btn1 setTitleColor:[UIColor colorWithHexString:@"#FFEFC0"] forState:UIControlStateHighlighted];
    btn1.titleLabel.font = [UIFont fontWithName:kFuturaMedium size:13];
    [backImgView2 addSubview:btn1];

    CGRect rec1 = [btn1.titleLabel.text boundingRectWithSize:CGSizeMake(backImgView2.size.width/2, ic1.size.height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont fontWithName:kFuturaMedium size:13]} context:nil];
    
    UIImageView *ig1 = [[UIImageView alloc] initWithFrame:CGRectMake(rec1.size.width  + 20 + (backImgView2.size.width/2 - rec1.size.width  - 20)/2 + 10 , 0, 20, 20)];
    ig1.centerY = btn1.centerY;
    ig1.image = [UIImage imageNamed:@"icon_idf23"];
    [backImgView2 addSubview:ig1];
    
    
    UIButton *btn2 = [[UIButton alloc] initWithFrame:CGRectMake(btn1.right, 0, backImgView2.size.width/2, ic1.size.height)];
    [btn2 setTitle:[NSString stringWithFormat:@"  %@",@"Face"] forState:UIControlStateNormal];
    [btn2 setTitle:[NSString stringWithFormat:@"  %@",@"Face"] forState:UIControlStateSelected];
    [btn2 setTitle:[NSString stringWithFormat:@"  %@",@"Face"] forState:UIControlStateHighlighted];
    [btn2 setImage:[UIImage imageNamed:@"icon_idf2-2"] forState:UIControlStateNormal];
    [btn2 setImage:[UIImage imageNamed:@"icon_idf2-2"] forState:UIControlStateSelected];
    [btn2 setImage:[UIImage imageNamed:@"icon_idf2-2"] forState:UIControlStateSelected];
    btn2.titleLabel.font = [UIFont fontWithName:kFuturaMedium size:13];
    [btn2 setTitleColor:[UIColor colorWithHexString:@"#FFEFC0"] forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor colorWithHexString:@"#FFEFC0"] forState:UIControlStateSelected];
    [btn2 setTitleColor:[UIColor colorWithHexString:@"#FFEFC0"] forState:UIControlStateHighlighted];
    [backImgView2 addSubview:btn2];
    
    CGRect rec2 = [btn2.titleLabel.text boundingRectWithSize:CGSizeMake(backImgView2.size.width/2, ic1.size.height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont fontWithName:kFuturaMedium size:13]} context:nil];
    
    UIImageView *ig2 = [[UIImageView alloc] initWithFrame:CGRectMake(backImgView2.size.width/2 + (backImgView2.size.width/2 - rec2.size.width  - 20)/2 + 30 + rec2.size.width, 0, 20, 20)];
    ig2.centerY = btn2.centerY;
    ig2.image = [UIImage imageNamed:@"icon_idf23"];
    [backImgView2 addSubview:ig2];
    
    UILabel *lab1 = [Utility createLabel:[UIFont fontWithName:kFuturaMedium size:13] color:[UIColor colorWithHexString:@"#F1F3F2"]];
    lab1.text = @"Full Name";
    [backImgView2 addSubview:lab1];
    lab1.frame = CGRectMake(20, ic1.bottom, 100, DimensionBaseIphone6(44));
    
    UILabel *nameLab = [Utility createLabel:[UIFont fontWithName:kFuturaMedium size:13] color:[UIColor colorWithHexString:@"#FFEFC0"]];
    nameLab.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:0.14];
    nameLab.frame = CGRectMake(20, lab1.bottom, backImgView2.size.width - 40 , DimensionBaseIphone6(44));
    nameLab.layer.cornerRadius = DimensionBaseIphone6(22);
    nameLab.layer.masksToBounds = YES;
    [backImgView2 addSubview:nameLab];
    
    UILabel *lab2 = [Utility createLabel:[UIFont fontWithName:kFuturaMedium size:13] color:[UIColor colorWithHexString:@"#F1F3F2"]];
    lab2.text = @"ID No.";
    [backImgView2 addSubview:lab2];
    lab2.frame = CGRectMake(20, nameLab.bottom, 100, DimensionBaseIphone6(44));
    
    UILabel *noLab = [Utility createLabel:[UIFont fontWithName:kFuturaMedium size:13] color:[UIColor colorWithHexString:@"#FFEFC0"]];
    noLab.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:0.14];
    noLab.frame = CGRectMake(20, lab2.bottom, backImgView2.size.width - 40 , DimensionBaseIphone6(44));
    noLab.layer.cornerRadius = DimensionBaseIphone6(22);
    noLab.layer.masksToBounds = YES;
    [backImgView2 addSubview:noLab];
    
    UILabel *lab3 = [Utility createLabel:[UIFont fontWithName:kFuturaMedium size:13] color:[UIColor colorWithHexString:@"#F1F3F2"]];
    lab3.text = @"Date Of Birth";
    [backImgView2 addSubview:lab3];
    lab3.frame = CGRectMake(20, noLab.bottom, 100, DimensionBaseIphone6(44));
    
    UILabel *dateLab = [Utility createLabel:[UIFont fontWithName:kFuturaMedium size:13] color:[UIColor colorWithHexString:@"#FFEFC0"]];
    dateLab.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:0.14];
    dateLab.frame = CGRectMake(20, lab3.bottom, backImgView2.size.width - 40 , DimensionBaseIphone6(44));
    dateLab.layer.cornerRadius = DimensionBaseIphone6(22);
    dateLab.layer.masksToBounds = YES;
    [backImgView2 addSubview:dateLab];
    
    nameLab.text = [NSString stringWithFormat:@"  %@",esString(self.nameStr)];
    noLab.text = [NSString stringWithFormat:@"  %@",esString(self.idNoStr)];
    dateLab.text = [NSString stringWithFormat:@"  %@",esString(self.birDateStr)];
    
    
    UIImageView *shadeImgView = [[UIImageView alloc] initWithFrame:CGRectMake((kScreenWidth - bgImg2.size.width)/2, DimensionBaseIphone6(24), bgImg2.size.width, bgImg2.size.height)];
    shadeImgView.image = bgImg2;
    [headView addSubview:shadeImgView];
    
    
    
}

- (void)clickOKBtn{
    [CreaditUtilsHelper boxShowLoadWithMessage:@""];
    NSMutableDictionary *muDic = @{
        @"gardens":esString(self.idStr),
        @"tuesday":@"tuesdayOrderDet",
        @"needn":@"neednOrderDet",
    }.mutableCopy;
    [BaseDataEngine apiForPath:kProductDetUrl method:kPostMethod parameter:muDic onCompleteSuccess:^(NSDictionary *responseDic) {
        [CreaditUtilsHelper hideLoadMessageBox];
        DLog(@"=====%@",responseDic);
        if ([responseDic[@"dim"] integerValue] != kSuccessCode) {
            [CreaditUtilsHelper boxShowErrorWithMessage:esString(responseDic[@"platform"]) duration:2.5f];
            return;
        }
        
        NSDictionary *dic = responseDic[@"recollecting"];
       
        NSDictionary *lauDic = dic[@"laughing"];
        
        if (PMObjectIsEmpty(lauDic)) {
            [self enterOrderH5Page];
            return;
        }
        if ([esString(lauDic[@"tumbled"]) isEqualToString:kMakemoneyg]) {
            [self goPersonalVertify];
        }
        else if ([esString(lauDic[@"tumbled"]) isEqualToString:kMakemoneyh]) {
            [self goWorkVertify];
        }
        else if ([esString(lauDic[@"tumbled"]) isEqualToString:kMakemoneyi]) {
            [self goContactVertify];
        }
        else if ([esString(lauDic[@"tumbled"]) isEqualToString:kMakemoneyj]) {
            [self goBankVertify];
        }
        
    } onCompleteFailur:^(NSError *error) {
        [CreaditUtilsHelper hideLoadMessageBox];
    } withIsForm:YES];
    
}

- (void)enterOrderH5Page{
    NSString *stTime = [NSString getNowTimeTimestamp:@"yyyyMMdd HH:mm:ss"];
    NSMutableDictionary *muDic = @{
        @"commissariat":esString([[NSUserDefaults standardUserDefaults] valueForKey:kOrderNumber]),
        @"tracked":@"trackedIdStr",
        @"rot":@"rotIdStr",
        @"thrown":@"thrownIdStr",
        @"object":@"objectIdStr",
    }.mutableCopy;
    [CreaditUtilsHelper boxShowLoadWithMessage:@""];
    [BaseDataEngine apiForPath:kByOrderIdGetUrl method:kPostMethod parameter:muDic onCompleteSuccess:^(NSDictionary *responseDic) {
        [CreaditUtilsHelper hideLoadMessageBox];
        if ([responseDic[@"dim"] integerValue] != kSuccessCode) {
            [CreaditUtilsHelper boxShowErrorWithMessage:esString(responseDic[@"platform"]) duration:2.5f];
            return;
        }
        [CreditServerHelper uploadMaiDianDataStartTimeStr:stTime andEndTimeStr:[NSString getNowTimeTimestamp:@"yyyyMMdd HH:mm:ss"] withTypeStr:@"9" withFirmly:esString(self.idStr) withSmaller:esString([[NSUserDefaults standardUserDefaults] valueForKey:kOrderNumber])];
        
        NSDictionary *dic = responseDic[@"recollecting"];
        
        [[CreditCore globleCore] jumpToPage:esString(dic[@"exulting"])];
        
        
    } onCompleteFailur:^(NSError *error) {
        [CreaditUtilsHelper hideLoadMessageBox];
    } withIsForm:YES];
}

#pragma mark ----personalVertify
- (void)goPersonalVertify{
    PersonVertifyController *vc = [[PersonVertifyController alloc] init];
    vc.idStr = esString(self.idStr);
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark ----workVertify
- (void)goWorkVertify{
    WorkInfoVertifyController *vc = [[WorkInfoVertifyController alloc] init];
    vc.idStr = esString(self.idStr);
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark ----contactVertify
- (void)goContactVertify{
    ContactVertifyController *vc = [[ContactVertifyController alloc] init];
    vc.idStr = esString(self.idStr);
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark ----bankVertify
- (void)goBankVertify{
    BankVertifyController *vc = [[BankVertifyController alloc] init];
    vc.idStr = esString(self.idStr);
    [self.navigationController pushViewController:vc animated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
